Scaling: Remove Instances
We'll cover the following
Removing the explicit instances#
Now that our new ASG instances are up and are serving requests through our load balancer, we can safely remove our explicit instances without causing any disruption. To do so, we just need to remove every reference to them from our main.yml
script, and redeploy:
- The entire
Instance
resource. - The entire
Instance2
resource. - The entire
Targets
property from theLoadBalancerTargetGroup
resource. - The
Ec2TagFilters
property from theStagingDeploymentGroup
resource. - The
InstanceEndpoint
andInstanceEndpoint2
outputs.
Now, let’s redeploy our infrastructure by running deploy-infra.sh
.
If we hit the load balancer endpoint now, we should see our traffic split between the two instances in our ASG. The other two instances have been terminated.
It’s time to checkpoint all our changes and push them to GitHub.
Note: All the code has been already added and we are pushing it on our repository as well.
/
- deploy-infra.sh
Adding capacity in a pinch is much easier now. From the Auto Scaling console (FIGURE 1), you can select your ASG (FIGURE 2) and edit the desired capacity setting (FIGURE 3). The number of EC2 instances will automatically reflect your desired capacity within a few seconds.
NOTE: All these figures are shown below.
In order to get a pictorial view of our developed cloudformation stack so far, below is the design view which shows the resources we created and their relationships.
In the next lesson, we will create separate environments for staging and production.